#!/bin/bash
cmake_minimum_required(VERSION 2.8.12)
project(fastbev)

set(CMAKE_BUILD_PYTHON $ENV{USE_Python})
set(CMAKE_BUILD_TYPE "Release")
# set(CMAKE_BUILD_TYPE "Debug")
set(arch ${CMAKE_HOST_SYSTEM_PROCESSOR})


find_package(CUDA REQUIRED)
find_package(Protobuf REQUIRED)
find_package(OpenCV)
find_package(yaml-cpp REQUIRED)
find_package(cv_bridge REQUIRED)
include_directories(${cv_bridge_INCLUDE_DIRS}) 
find_package(message_filters REQUIRED)
include_directories(${message_filters_INCLUDE_DIRS})

set(tensorrt_dir /home/xd/TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6/TensorRT-8.5.1.7)
set(tensorrt_lib ${tensorrt_dir}/lib)
set(tensorrt_target_lib ${tensorrt_dir}/targets/x86_64-linux-gnu/lib)
set(tensorrt_include ${tensorrt_dir}/include)


include_directories(
  ${Protobuf_INCLUDE_DIRS}
  ${CUDA_INCLUDE_DIRS}
  ${tensorrt_include}
  $ENV{Python_Inc}
  src/common
  src/
)

link_directories(
  ${cuda_lib}
  ${tensorrt_lib}
  build
)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

file(GLOB_RECURSE CORE_FILES 
  src/fastbev/*.cu 
  src/fastbev/*.cpp
  src/common/tensor.cu
  src/common/tensorrt.cpp
)

####################### libfastbev_core.so ##########################
cuda_add_library(fastbev_core SHARED 
  ${CORE_FILES}
)

target_link_libraries(fastbev_core
  # libcudart.so
  # libcublasLt.so
  libnvinfer.so
  # libspconv.so
  ${Protobuf_LIBRARIES}
  libnvinfer_plugin.so
  ${OpenCV_LIBS}
  ${cv_bridge_LIBRARIES} 
  ${message_filters_LIBRARIES}
)
#######################################################################


option(ROS_ENABLE "option for ros enable" OFF)
if(ROS_ENABLE)
	add_definitions(-DROS_ENABLE)
	find_package(roscpp REQUIRED)
  find_package(visualization_msgs REQUIRED)
	include_directories(
	${roscpp_INCLUDE_DIRS}
	)
endif()

if(ROS_ENABLE)
	target_link_libraries(fastbev_core ${roscpp_LIBRARIES})
endif()

####################### fastbev program #############################
cuda_add_executable(fastbev 
  src/main.cpp
  src/fastbevdetect.cpp
  src/fastbevdetect.h
)

target_link_libraries(fastbev
  fastbev_core
  libnvinfer.so
  # libspconv.so
  ${Protobuf_LIBRARIES}
  libnvinfer_plugin.so
  ${OpenCV_LIBS}
  ${YAML_CPP_LIBRARIES}
)
#######################################################################

